#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_dckerr.info <<'%EOF%'
   rsp_dckerr
   ----------
   Molecule:         O3
   Wave Function:    MCSCF (RAS)
   Test Purpose:     Single-point calculation of the DC-Kerr effect
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_dckerr.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
Calculation of DC-Kerr effect

    1    2  Y  Z
        8.    2
OS         -.0014349248             .0000000000             .0000000000
OP        1.2641677124            2.0463120050             .0000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_dckerr.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**WAVE FUNCTIONS
.HF
.MP2
.MCSCF
*SCF INPUT
.DOUBLY OCCUPIED
 6 4 1 1
*CONFIGURATION INPUT
.SYMMETRY
 1
.SPIN MUL
 1
.INACTIVE
 4 2 0 0
.ELECTRONS
 12
.RAS1 SPACE
 2 2 1 0
.RAS1 HOLES
 0 2
.RAS2 SPACE
 0 0 1 1
.RAS3 SPACE
 1 1 0 0
.RAS3 ELECTRONS
 0 2
**RESPONSE
*CUBIC
.MAX IT
 40
.DC-KER
.FREQUE
 2
 0.0 0.0592
.APROP
ZDIPLEN
.BPROP
ZDIPLEN
.CPROP
ZDIPLEN
.DPROP
ZDIPLEN
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_dckerr.check
cat >>rsp_dckerr.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 3 * 2 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 27 * 21 * 12 * 9" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2`
CTRL[1]=2
ERROR[1]="SYMMETRY NOT CORRECT"

# SCF energy
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-224\.29003482" $log | wc -l`
TEST[2]=`expr	$CRIT1`
CTRL[2]=1
ERROR[2]="SCF ENERGY NOT CORRECT"

# MP2 energy
CRIT1=`$GREP "\= MP2 second order energy *\: * \-224\.963993" $log | wc -l`
TEST[3]=`expr	$CRIT1`
CTRL[3]=1
ERROR[3]="MP2 ENERGY NOT CORRECT"

# MCSCF energy
CRIT1=`$GREP "Final MCSCF energy\: * \-224\.510751246" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="MCSCF ENERGY NOT CORRECT"

# Response calculation
CRIT1=`$GREP "Second hyperpolarizability calculation \: * CRCAL\= T" $log | wc -l`
CRIT2=`$GREP "\- Dc\-Kerr calculation" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2`
CTRL[5]=2
ERROR[5]="RESPONSE CALCULATION NOT CORRECT"

# Gamma values
CRIT1=`$GREP "\@ gamma\(Z\;Z\,Z\,Z\) * 207\.46" $log | wc -l`
CRIT2=`$GREP "\@ gamma\(Z\;Z\,Z\,Z\) * 214\.81" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2`
CTRL[6]=4
ERROR[6]="GAMMA VALUES NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
